package com.xm.service.reception_desk;

import com.xm.dao.reception_desk.OrdersDao;
import com.xm.entity.Orders;
import com.xm.exception.SqlErrorException;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.List;

/**
 * 订单Service
 * @author 康文程
 * @date 2024-1-8 下午 09:18
 */
public class OrdersService {
    private final OrdersDao dao = new OrdersDao();
    /**
     * 新增订单
     * @param orders 订单
     * @throws SqlErrorException 抛出错误
     */
    public void insertOrder(Orders orders) throws SqlErrorException {
        dao.insertOrder(orders);
    }
    /**
     * 根据订单ID查询订单到期时间
     *
     * @param orderId 订单ID
     * @return 订单到期剩余时间（分钟）
     * @throws SqlErrorException SQL执行异常
     */
    public int getOrderExpirationTimeByOrderId(String orderId) throws SqlErrorException {
        return dao.getOrderExpirationTimeByOrderId(orderId);
    }

    public int getOrderExpirationTime(Integer informationId) throws SqlErrorException {
        return dao.getOrderExpirationTime(informationId);
    }
    /**
     * 根据订单ID修改订单状态
     *
     * @param orderId 订单ID
     * @param status  订单状态
     * @throws SqlErrorException SQL执行异常
     */
    public void updateOrderStatusByOrderId(String orderId, int status) throws SqlErrorException {
        dao.updateOrderStatusByOrderId(orderId, status);
    }
    /**
     * 根据订单ID查询订单金额
     * @param orderId 订单ID
     * @return 订单金额
     * @throws SqlErrorException SQL执行异常
     */
    public BigDecimal getPaymentPriceByOrderId(String orderId) throws SqlErrorException {
        return dao.getPaymentPriceByOrderId(orderId);
    }
    /**
     * 根据用户信息ID查询订单列表
     * @param informationId 用户信息ID
     * @return 订单列表
     * @throws SqlErrorException SQL执行异常
     */
    public List<Orders> getOrdersByInformationId(Integer informationId,String status,String searchInput) throws SQLException, ParseException {
        return dao.getOrdersByInformationId(informationId,status,searchInput);
    }

    /**
     * 根据用户信息ID,订单ID查询订单
     * 根据订单状态查询
     * @param informationId 用户信息ID
     * @param ordersId 订单信息ID
     * @return 订单列表
     * @throws SqlErrorException SQL执行异常
     */
    public  List<Orders> getOrdersDetails(Integer informationId,String ordersId) throws SQLException {
        return dao.getOrdersDetails(informationId,ordersId);
    }

    /**
     * 根据账户ID,订单状态查询订单数量
     * @param informationId 用户ID
     * @param orderState 订单状态
     * @return 订单数量
     * @throws SqlErrorException SQL执行异常
     */
    public int getOrderCount(Integer informationId,Integer orderState) throws SqlErrorException {
        return dao.getOrderCount(informationId,orderState);
    }
    /**
     * 根据账户ID,订单号删除订单
     *
     * @param informationId 用户ID
     * @param ordersId      订单号
     * @return true/false
     * @throws SqlErrorException SQL执行异常
     */
    public boolean getOrderDelete(int informationId, String ordersId) throws SqlErrorException {
        return dao.getOrderDelete(informationId,ordersId);
    }
    /**
     * 查询是否有被选中的地址
     * @param informationId 用户信息Id
     * @return true 有 false 无
     * @throws SqlErrorException 抛出错误
     */
    public boolean checkUnselectedAddress(int informationId) throws SqlErrorException {
        return dao.checkUnselectedAddress(informationId);
    }
}
